/*
 * @lc app=leetcode.cn id=69 lang=java
 *
 * [69] x 的平方根
 */

// @lc code=start
class Solution {
    public int mySqrt(int x) {
        int left = 1, right = x / 2 + 1;
        while (left <= right) {
            int middle = left + (right - left) / 2;
            if (middle == x / 2) {
                return middle;
            }
            if (middle < x /2) {
                right = middle + 1;
            }
            if (middle > x /2) {
                left = middle - 1;
            }
        }
        return right;
    }
}
// @lc code=end
